﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class UploadFile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string StoreId = Context.Request["StoreId"];
        string Type = Context.Request["Type"];
        string FullFilePath = string.Empty;
        if (string.IsNullOrEmpty(StoreId) || string.IsNullOrEmpty(Type))
        {
            Context.Response.Write("StoreId或Type值为空");
        }
        else
        {
            string path = CreateDirectory(ConfigurationManager.AppSettings["UploadFilePath"]+ DateTime.Now.ToString("yyyy-MM-dd") + @"\" + StoreId + @"\" + Type + @"\");
            foreach (string f in Context.Request.Files.AllKeys)
            {
                HttpPostedFile file = Context.Request.Files[f];
                FullFilePath = path + file.FileName;
                file.SaveAs(FullFilePath);
            }
            if (File.Exists(FullFilePath))
            {
                Context.Response.Write("上传成功");
            }
            else
            {
                Context.Response.Write("上传失败");
            }

        }
        Context.Response.End();
    }
    string CreateDirectory(string path)
    {
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        return path;
    }
}
